home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 January / january_2001.iso / intercd / root / ^4Developers / VB / visbasdb / VBDB / VBDB Code / VB6 Code / Class 6 / Example6-6DE.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-17  |  7.6 KB  |  267 lines

  1. VERSION 5.00
  2. Begin VB.Form frmAuthors 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Authors"
  5.    ClientHeight    =   2625
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   4680
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   2625
  13.    ScaleWidth      =   4680
  14.    StartUpPosition =   3  'Windows Default
  15.    Begin VB.CommandButton cmdDone 
  16.       Caption         =   "Do&ne"
  17.       Height          =   375
  18.       Left            =   3240
  19.       TabIndex        =   13
  20.       TabStop         =   0   'False
  21.       Top             =   2160
  22.       Width           =   1215
  23.    End
  24.    Begin VB.CommandButton cmdDelete 
  25.       Caption         =   "&Delete"
  26.       Height          =   375
  27.       Left            =   1680
  28.       TabIndex        =   12
  29.       TabStop         =   0   'False
  30.       Top             =   2160
  31.       Width           =   1215
  32.    End
  33.    Begin VB.CommandButton cmdEdit 
  34.       Caption         =   "&Edit"
  35.       Height          =   375
  36.       Left            =   120
  37.       TabIndex        =   11
  38.       TabStop         =   0   'False
  39.       Top             =   2160
  40.       Width           =   1215
  41.    End
  42.    Begin VB.CommandButton cmdCancel 
  43.       Caption         =   "&Cancel"
  44.       Height          =   375
  45.       Left            =   3240
  46.       TabIndex        =   10
  47.       TabStop         =   0   'False
  48.       Top             =   1680
  49.       Width           =   1215
  50.    End
  51.    Begin VB.CommandButton cmdSave 
  52.       Caption         =   "&Save"
  53.       Height          =   375
  54.       Left            =   1680
  55.       TabIndex        =   9
  56.       TabStop         =   0   'False
  57.       Top             =   1680
  58.       Width           =   1215
  59.    End
  60.    Begin VB.CommandButton cmdAddNew 
  61.       Caption         =   "&Add New"
  62.       Height          =   375
  63.       Left            =   120
  64.       TabIndex        =   8
  65.       TabStop         =   0   'False
  66.       Top             =   1680
  67.       Width           =   1215
  68.    End
  69.    Begin VB.CommandButton cmdNext 
  70.       Caption         =   "Next =>"
  71.       Height          =   255
  72.       Left            =   2520
  73.       TabIndex        =   7
  74.       TabStop         =   0   'False
  75.       Top             =   1320
  76.       Width           =   1215
  77.    End
  78.    Begin VB.CommandButton cmdPrevious 
  79.       Caption         =   "<= Previous"
  80.       Height          =   255
  81.       Left            =   1080
  82.       TabIndex        =   6
  83.       TabStop         =   0   'False
  84.       Top             =   1320
  85.       Width           =   1215
  86.    End
  87.    Begin VB.TextBox txtYearBorn 
  88.       DataField       =   "Year Born"
  89.       DataMember      =   "comAuthors"
  90.       DataSource      =   "denBooks"
  91.       Height          =   285
  92.       Left            =   1200
  93.       Locked          =   -1  'True
  94.       MaxLength       =   4
  95.       TabIndex        =   2
  96.       Text            =   "Text"
  97.       Top             =   840
  98.       Width           =   1215
  99.    End
  100.    Begin VB.TextBox txtAuthor 
  101.       DataField       =   "Author"
  102.       DataMember      =   "comAuthors"
  103.       DataSource      =   "denBooks"
  104.       Height          =   285
  105.       Left            =   1200
  106.       Locked          =   -1  'True
  107.       TabIndex        =   1
  108.       Text            =   "Text2"
  109.       Top             =   480
  110.       Width           =   3375
  111.    End
  112.    Begin VB.TextBox txtAuthorID 
  113.       DataField       =   "Au_ID"
  114.       DataMember      =   "comAuthors"
  115.       DataSource      =   "denBooks"
  116.       Height          =   285
  117.       Left            =   1200
  118.       Locked          =   -1  'True
  119.       TabIndex        =   3
  120.       TabStop         =   0   'False
  121.       Text            =   "Text1"
  122.       Top             =   120
  123.       Width           =   1215
  124.    End
  125.    Begin VB.Label Label3 
  126.       Caption         =   "Year Born"
  127.       Height          =   255
  128.       Left            =   120
  129.       TabIndex        =   5
  130.       Top             =   840
  131.       Width           =   1215
  132.    End
  133.    Begin VB.Label Label2 
  134.       Caption         =   "Author Name"
  135.       Height          =   255
  136.       Left            =   120
  137.       TabIndex        =   4
  138.       Top             =   480
  139.       Width           =   1215
  140.    End
  141.    Begin VB.Label Label1 
  142.       Caption         =   "Author ID"
  143.       Height          =   255
  144.       Left            =   120
  145.       TabIndex        =   0
  146.       Top             =   120
  147.       Width           =   1215
  148.    End
  149. Attribute VB_Name = "frmAuthors"
  150. Attribute VB_GlobalNameSpace = False
  151. Attribute VB_Creatable = False
  152. Attribute VB_PredeclaredId = True
  153. Attribute VB_Exposed = False
  154. Option Explicit
  155. Private Sub ValidateData(AllOK As Boolean)
  156. Dim Message As String
  157. Dim InputYear As Integer, CurrentYear As Integer
  158. AllOK = True
  159. Message = ""
  160. 'Check for name
  161. If Len(txtAuthor.Text) = 0 Then
  162.   Message = "You must enter an Author Name." + vbCrLf
  163.   txtAuthor.SetFocus
  164.   AllOK = False
  165. End If
  166. 'Check length and range on Year Born
  167. InputYear = Val(txtYearBorn.Text)
  168. CurrentYear = Val(Format(Now, "yyyy"))
  169. If Len(txtYearBorn.Text) <> 0 Then
  170.   If InputYear > CurrentYear Or InputYear < CurrentYear - 150 Then
  171.     Message = Message + "Year Born must be between" & Str(CurrentYear - 150) & " and" & Str(CurrentYear) & "."
  172.     txtYearBorn.SetFocus
  173.     AllOK = False
  174.   End If
  175. End If
  176. If Not (AllOK) Then
  177.   MsgBox Message, vbOKOnly + vbInformation, "Validation Error"
  178. End If
  179. End Sub
  180. Private Sub cmdAddNew_Click()
  181. Call SetState("Add")
  182. End Sub
  183. Private Sub cmdCancel_Click()
  184. Call SetState("View")
  185. End Sub
  186. Private Sub cmdDelete_Click()
  187. Dim Response As Integer
  188. Response = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion + vbDefaultButton2, "Delete")
  189. If Response = vbNo Then
  190.   Exit Sub
  191. End If
  192. End Sub
  193. Private Sub cmdEdit_Click()
  194. Call SetState("Edit")
  195. End Sub
  196. Private Sub cmdNext_Click()
  197. denBooks.rscomAuthors.MoveNext
  198. If denBooks.rscomAuthors.EOF Then
  199.   Beep
  200.   denBooks.rscomAuthors.MoveLast
  201. End If
  202. End Sub
  203. Private Sub cmdPrevious_Click()
  204. denBooks.rscomAuthors.MovePrevious
  205. If denBooks.rscomAuthors.BOF Then
  206.   Beep
  207.   denBooks.rscomAuthors.MoveFirst
  208. End If
  209. End Sub
  210. Private Sub cmdSave_Click()
  211. Dim Valid As Boolean
  212. Call ValidateData(Valid)
  213. If Not (Valid) Then Exit Sub
  214. MsgBox "Record saved.", vbOKOnly + vbInformation, "Save"
  215. Call SetState("View")
  216. End Sub
  217. Private Sub SetState(AppState As String)
  218. Select Case AppState
  219. Case "View"
  220.   txtAuthorID.BackColor = vbWhite
  221.   txtAuthor.Locked = True
  222.   txtYearBorn.Locked = True
  223.   cmdPrevious.Enabled = True
  224.   cmdNext.Enabled = True
  225.   cmdAddNew.Enabled = True
  226.   cmdSave.Enabled = False
  227.   cmdCancel.Enabled = False
  228.   cmdEdit.Enabled = True
  229.   cmdDelete.Enabled = True
  230.   cmdDone.Enabled = True
  231.   txtAuthor.SetFocus
  232. Case "Add", "Edit"
  233.   txtAuthorID.BackColor = vbRed
  234.   txtAuthor.Locked = False
  235.   txtYearBorn.Locked = False
  236.   cmdPrevious.Enabled = False
  237.   cmdNext.Enabled = False
  238.   cmdAddNew.Enabled = False
  239.   cmdSave.Enabled = True
  240.   cmdCancel.Enabled = True
  241.   cmdEdit.Enabled = False
  242.   cmdDelete.Enabled = False
  243.   cmdDone.Enabled = False
  244.   txtAuthor.SetFocus
  245. End Select
  246. End Sub
  247. Private Sub Form_Activate()
  248. Call SetState("View")
  249. End Sub
  250. Private Sub txtAuthor_KeyPress(KeyAscii As Integer)
  251. If KeyAscii = vbKeyReturn Then
  252.   txtYearBorn.SetFocus
  253.   Exit Sub
  254. End If
  255. End Sub
  256. Private Sub txtYearBorn_KeyPress(KeyAscii As Integer)
  257. If KeyAscii = vbKeyReturn Then
  258.   txtAuthor.SetFocus
  259.   Exit Sub
  260. End If
  261. If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9")) Or KeyAscii = vbKeyBack Then
  262.   Exit Sub
  263.   Beep
  264.   KeyAscii = 0
  265. End If
  266. End Sub
  267.